package services

import (
	"lottery/dao"
	"lottery/datasource"
	"lottery/models"
)

type UserService interface {
	Get(id int) (has bool, data *models.TbUser)
	GetByUsername(username string) (has bool, data *models.TbUser)
	GetByOpenId(openId string) (has bool, data *models.TbUser)
	GetAll() []models.TbUser
	IsUserExist(username string) bool
	Update(data *models.TbUser, columns []string) error
	Create(data *models.TbUser) error
	Delete(id int) error
}

type userService struct {
	dao *dao.UserDao
}

func (s *userService) Get(id int) (has bool, data *models.TbUser) {
	return s.dao.Get(id)
}

func (s *userService) GetByUsername(username string) (has bool, data *models.TbUser) {
	return s.dao.GetByUsername(username)
}

func (s *userService) GetByOpenId(openId string) (has bool, data *models.TbUser) {
	return s.dao.GetByOpenId(openId)
}

func (s *userService) GetAll() []models.TbUser {
	return s.dao.GetAll()
}

func (s *userService) IsUserExist(username string) bool {
	return s.dao.IsUserExist(username)
}

func (s *userService) Update(data *models.TbUser, columns []string) error {
	return s.dao.Update(data, columns)
}

func (s *userService) Create(data *models.TbUser) error {
	return s.dao.Create(data)
}

func (s *userService) Delete(id int) error {
	return s.dao.Delete(id)
}

func NewUserService() UserService {
	return &userService{dao: dao.NewUserDao(datasource.InstanceDbMaster())}
}
